﻿#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.Runtime.dll"

#load "Client.fs"

open Client
open Microsoft.SharePoint.Client
open Microsoft.SharePoint.Client.Sharing
open Microsoft.SharePoint.Client.Utilities
open Microsoft.SharePoint.Client.WebParts
open Microsoft.SharePoint.Client.Application
open System.Security;

// =======================================================
// Installing apps on sites
// =======================================================

let web = Client.Context.Web

Client.Load web

let appInstances = AppCatalog.GetAppInstances(Client.Context, Client.Context.Web)
Client.Load appInstances

for app in appInstances do
    let msg = app.Title + " | " + app.RemoteAppUrl + " | " + app.AppPrincipalId
    printfn "%s\n" msg

// TODO: Enable/Disable sideloading feature

let stream = System.IO.File.OpenRead("C:\Projects\InsideDMS.app")
let appInst = Client.Context.Web.LoadAndInstallApp(stream)
Client.Load appInst
